﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SisLegal.Model;

namespace SisLegal.Conciliation
{
    public partial class ConciliationNewForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Error.Text = "";
                /*DDL_Participation_Seal.DataSource = Enumeration.GetAll<eParticipation_Seal_Fiscal_Folder>();
                DDL_Participation_Seal.DataTextField = "Value";
                DDL_Participation_Seal.DataValueField = "Key";
                DDL_Participation_Seal.DataBind();*/
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.Error.Text = "Error : <br>";
            if (this.txtNroConciliation.Text == "")
            {
                this.Error.Text = " * Ingrese Numero de Conciliacion <br>";
                this.txtNroConciliation.Focus();
                return;
            }

            Model.ConciliationManager manager = new Model.ConciliationManager();
            Model.Conciliation obj = new Model.Conciliation();

            if (txtDateInvitation.Text == "") { txtDateInvitation.Text = "0001-01-01"; }
            if (txtFirstCitation.Text == "") { txtFirstCitation.Text = "0001-01-01"; }
            if (txtSecondCitation.Text == "") { txtSecondCitation.Text = "0001-01-01"; }
            
            obj.NroConciliation = this.txtNroConciliation.Text.Trim();
            obj.City = txtCity.Text.Trim();
            obj.Solicitante = txtSolicitante.Text.Trim();
            obj.Invitado = txtInvitado.Text.Trim();
            obj.ParticipationSeal = Convert.ToInt32(this.DDL_Participation_Seal.SelectedItem.Value);
            obj.DateInvitation = Convert.ToDateTime(this.txtDateInvitation.Text);
            obj.FirstCitation = Convert.ToDateTime(this.txtFirstCitation.Text);
            obj.SecondCitation = Convert.ToDateTime(this.txtSecondCitation.Text);
            obj.Sumilla = this.txtSumilla.Text.Trim();
            obj.Observaciones = this.txtObservaciones.Text.Trim();

            manager.Save(obj);

            Response.Redirect("/Conciliation/ConciliationListView.aspx");

        }

    }
}